package com.zzc.controller;


import com.zzc.common.JsonResult;
import com.zzc.pojo.AdminUser;
import com.zzc.service.AdminUserService;
import com.zzc.service.MenuService;
import com.zzc.common.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author zhouzhicheng
 * @version 1.0  2020/12/29
 */
@Controller
public class SystemController {
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private MenuService menuService;
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "login.html";
    }
    @RequestMapping("/doLogin")
    @ResponseBody
    public JsonResult doLogin(String email,String password,HttpSession session){
        JsonResult result = adminUserService.doLogin(email, password);
        if (result.getStatus()){
            session.setAttribute(Const.LOGIN_INFO, result.getResult());
        }
        return result;
    }
    @RequestMapping("/side")
    @ResponseBody
    public JsonResult getMenu(HttpSession session){
        AdminUser user = (AdminUser) session.getAttribute(Const.LOGIN_INFO);
        if (user == null) {
            return JsonResult.getResultFailed("请先登录！再进行操作");
        }
        return menuService.selectMenuListByUserId(user.getId());
    }

}
